package com.jcli._自己的想法;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class LocalOneNoteViewer extends JFrame {

    // Declare Swing components
    private JButton getDataButton;
    private JList<String> dataList;

    public LocalOneNoteViewer() {
        initializeUI();
    }

    private void initializeUI() {
        setTitle("Local OneNote Viewer");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create Swing components
        getDataButton = new JButton("Get Local OneNote Data");
        getDataButton.addActionListener(e -> fetchDataFromLocalOneNote());

        dataList = new JList<>();

        // Layout the components
        setLayout(new BorderLayout());
        add(getDataButton, BorderLayout.NORTH);
        add(new JScrollPane(dataList), BorderLayout.CENTER);
    }

    private void fetchDataFromLocalOneNote() {
        // Specify the path where OneNote notebooks are stored locally
        String localOneNotePath = "D:\\li\\Documents";

        // Get a list of notebooks
        List<String> notebooks = new ArrayList<>();
        File notebooksDir = new File(localOneNotePath);
        if (notebooksDir.exists() && notebooksDir.isDirectory()) {
            File[] notebookFolders = notebooksDir.listFiles(File::isDirectory);
            if (notebookFolders != null) {
                for (File notebookFolder : notebookFolders) {
                    notebooks.add(notebookFolder.getName());
                }
            }
        }

        // Update the Swing component with the retrieved data
        dataList.setListData(notebooks.toArray(new String[0]));
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new LocalOneNoteViewer().setVisible(true));
    }
}
